//
//  SNSettingInfoCell.m
//  project
//
//  Created by 黄建华 on 2018/12/12.
//  Copyright © 2018年 黄建华. All rights reserved.
//

#import "SNSettingInfoCell.h"

@implementation SNSettingInfoCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    
    return self;
}

- (void)createView {
    _setView = [[UIView alloc] init];
    [self addSubview:_setView];
}

- (void)updateCellWithModel:(NSString *)title withHeight:(CGFloat)height
{
    _setView.frame = SNFRAME(0, 0, HHHWIDTH, height);
    [_setView removeAllSubviews];
    
    
    UIImageView *imageV = [[UIImageView alloc]init];
    UILabel *labelL = [[UILabel alloc] init];
    labelL.font = SNFONT(17.0);
    labelL.textAlignment = NSTextAlignmentLeft;
    labelL.adjustsFontSizeToFitWidth = YES;
    
    if ([title isEqualToString:SN_Text(@"我的好友")]) {
        imageV.frame = SNFRAME(20, 7.5, 35, 35);
        imageV.image = [UIImage imageNamed:@"好友"];
        [_setView addSubview:imageV];
        
        labelL.frame = SNFRAME(imageV.right + 15, 14, 200, 20);
        [_setView addSubview:labelL];
        labelL.text = title;
        
        UIButton *redButton = [[UIButton alloc] init];
        float width = [NSObject widthOfString:SN_Text(@"我的好友") font:SNFONT(17) height:20] + 10;
        redButton.frame = SNFRAME(labelL.left +width, labelL.top + 6, 8, 8);
        redButton.layer.masksToBounds = YES;
        redButton.layer.cornerRadius = 4;
        [_setView addSubview:redButton];
        if (SN_PublicClass.isFriendNewMessage) {
            redButton.hidden = NO;
        }
        else
        {
            redButton.hidden = YES;
        }
    }
    
    if ([title isEqualToString:SN_Text(@"个人设置1")]) {
        imageV.frame = SNFRAME(20, 7.5, 35, 35);
        imageV.image = [UIImage imageNamed:@"个人设置"];
        [_setView addSubview:imageV];
        
        labelL.frame = SNFRAME(imageV.right + 15, 14, 200, 20);
        [_setView addSubview:labelL];
        labelL.text = title;
    }
    
    if ([title isEqualToString:SN_Text(@"连接")] || [title isEqualToString:SN_Text(@"帮助与反馈")]) {
        labelL.frame = SNFRAME(15, 14, 200, 20);
        [_setView addSubview:labelL];
        labelL.text = title;
        labelL.textColor = SNCOLORGRAY;
        labelL.font = SNFONT(16.0);
    }
    
    if ([title isEqualToString:SN_Text(@"Strava")]) {
        imageV.frame = SNFRAME(20, 7.5, 35, 35);
        imageV.image = [UIImage imageNamed:@"Strava"];
        [_setView addSubview:imageV];
        
        labelL.frame = SNFRAME(imageV.right + 15, 14, 200, 20);
        [_setView addSubview:labelL];
        labelL.text = title;
        if (SN_PublicClass.showStravaToken) {
            labelL.text = [NSString stringWithFormat:@"%@ (%@)",SN_Text(@"Strava"),SN_Text(@"已授权")];
        }
        else
        {
            labelL.text = [NSString stringWithFormat:@"%@ (%@)",SN_Text(@"Strava"),SN_Text(@"未授权")];
        }
        
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(_setView.right - 44, 10, 30, 30)];
        [imageView setImage:UIImageNamed(@"进入(1)")];
        [_setView addSubview:imageView];
    }
    
    if ([title isEqualToString:SN_Text(@"关联天猫精灵")]) {
        imageV.frame = SNFRAME(20, 7.5, 35, 35);
        imageV.image = [UIImage imageNamed:@"icon-40"];
        [_setView addSubview:imageV];
        
        labelL.frame = SNFRAME(imageV.right + 15, 14, 200, 20);
        [_setView addSubview:labelL];
        labelL.text = title;
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(_setView.right - 44, 10, 30, 30)];
        [imageView setImage:UIImageNamed(@"进入(1)")];
        [_setView addSubview:imageView];
    }
    
    if ([title isEqualToString:SN_Text(@"苹果健康")]) {
        imageV.frame = SNFRAME(20, 7.5, 35, 35);
        imageV.image = [UIImage imageNamed:@"苹果健康"];
        [_setView addSubview:imageV];
        
        labelL.frame = SNFRAME(imageV.right + 15, 14, 200, 20);
        [_setView addSubview:labelL];
        labelL.text = title;
        
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(_setView.right - 44, 10, 30, 30)];
        [imageView setImage:UIImageNamed(@"进入(1)")];
        [_setView addSubview:imageView];
    }
    
    if ([title isEqualToString:SN_Text(@"意见反馈1")]) {
        imageV.frame = SNFRAME(20, 7.5, 35, 35);
        imageV.image = [UIImage imageNamed:@"意见反馈"];
        [_setView addSubview:imageV];
        
        labelL.frame = SNFRAME(imageV.right + 15, 14, 200, 20);
        [_setView addSubview:labelL];
        labelL.text = title;
        
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(_setView.right - 44, 10, 30, 30)];
        [imageView setImage:UIImageNamed(@"进入(1)")];
        [_setView addSubview:imageView];
    }
    
    if ([title isEqualToString:SN_Text(@"退出当前登录账号")])
    {
        _loginOutButton = [[UIButton alloc] init];
        _loginOutButton.frame = SNFRAME(20,5, HHHWIDTH -40, 40);
        _loginOutButton.backgroundColor = SNCOLORBLACK;
        _loginOutButton.layer.cornerRadius = 4.0;
        [_loginOutButton setTitle:title forState:UIControlStateNormal];
        [_loginOutButton setTitleColor:SNCOLORWHITE forState:UIControlStateNormal];
        [_loginOutButton setTitleColor:SNCOLORGRAYLINE forState:UIControlStateHighlighted];
        [_setView addSubview:_loginOutButton];
    }
}

@end
